{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ed2bedb8",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d0300f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%html\n",
    "<style>\n",
    ".cell-output-ipywidget-background {\n",
    "    background-color: transparent !important;\n",
    "}\n",
    ":root {\n",
    "    --jp-widgets-color: var(--vscode-editor-foreground);\n",
    "    --jp-widgets-font-size: var(--vscode-editor-font-size);\n",
    "}  \n",
    "</style>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11f14c1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from dotenv import load_dotenv\n",
    "from run import RunConfig\n",
    "from run_rl import train\n",
    "from tau_bench.types import TauBenchPolicyConfig, TauBenchTrainingConfig\n",
    "\n",
    "import art\n",
    "\n",
    "load_dotenv()\n",
    "\n",
    "MODEL_NAME = \"003\"\n",
    "model = art.TrainableModel(\n",
    "    name=MODEL_NAME,\n",
    "    project=\"tau-bench\",\n",
    "    base_model=\"Qwen/Qwen2.5-32B-Instruct\",\n",
    "    config=TauBenchPolicyConfig(\n",
    "        training_config=TauBenchTrainingConfig(\n",
    "            trajectories_per_group=16,\n",
    "            groups_per_step=8,\n",
    "            learning_rate=2e-6,\n",
    "            eval_steps=10,\n",
    "            val_set_size=60,\n",
    "            training_dataset_size=32,\n",
    "            num_epochs=1000,\n",
    "            train_mode=\"sync_rl\",\n",
    "        ),\n",
    "        run_config=RunConfig(\n",
    "            model_provider=\"hosted_vllm\",\n",
    "            user_model_provider=\"openai\",\n",
    "            model=MODEL_NAME,\n",
    "            user_model=\"gpt-4o\",\n",
    "            agent_strategy=\"tool-calling-rl\",\n",
    "            temperature=1.0,\n",
    "            task_split=\"test\",\n",
    "            log_dir=\"rl_results\",\n",
    "            skip_eval=False,\n",
    "        ),\n",
    "    ),\n",
    "    _internal_config=art.dev.InternalModelConfig(\n",
    "        engine_args=art.dev.EngineArgs(\n",
    "            tensor_parallel_size=torch.cuda.device_count(), gpu_memory_utilization=0.65\n",
    "        ),\n",
    "        torchtune_args=art.dev.TorchtuneArgs(\n",
    "            model=\"qwen2_5_32b_instruct\", model_type=\"QWEN2\", async_weight_syncing=True\n",
    "        ),\n",
    "    ),\n",
    ")\n",
    "await train(model)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
